<script lang="ts" setup>
import { reactive, defineEmits } from "vue"
import { HttpStatusCode } from "axios"
import { ElMessage } from "element-plus"
import { energyNature } from '../../../../enums/PersonalChannel'
import { addNewCarClue } from '../../../../api/newCarClue'

const emits = defineEmits(['increase', 'closeShow'])
let formLabelAlign = reactive<NewCarClue>({
  //线索名称
  clueName: '',
  //品牌
  brand: '',
  //指导价
  cluePrice: 0,
  //能源种类
  energy: null,
  //排放标准
  emissionStandard: '',
  //排量/变速箱
  gearbox: '',
  //所在地
  location: '',
  //联系电话
  phone: '',
  //车辆描述
  description: '',
  useCoin: 0
})
const submitData = async () => {
  const res = await addNewCarClue(formLabelAlign)
  if(res.statusCode === HttpStatusCode.Created) {
    ElMessage({
      message: '添加成功',
      type: 'success',
    })
    emits('increase', 1, '')
    emits('closeShow')
  } else {
    ElMessage({
      message: '添加失败',
      type: 'error',
    })
  }
}
</script>

<template>
  <el-form
      label-position="top"
      label-width="100px"
      :model="formLabelAlign"
      style="max-width: 460px"
  >
    <el-form-item label="线索名称">
      <el-input v-model="formLabelAlign.clueName" />
    </el-form-item>
    <el-form-item label="品牌">
      <el-input v-model="formLabelAlign.brand" />
    </el-form-item>
    <el-form-item label="指导价(万)">
      <el-input-number v-model="formLabelAlign.cluePrice" :precision="1" :step="0.1">
      </el-input-number>
    </el-form-item>
    <el-form-item label="车辆所在地">
      <el-input v-model="formLabelAlign.location" />
    </el-form-item>
    <el-form-item label="能源种类">
      <el-select v-model="formLabelAlign.energy" placeholder="选择能源种类">
        <el-option
            v-for="item in energyNature"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="排放标准">
      <el-input v-model="formLabelAlign.emissionStandard" :disabled="formLabelAlign.energy === 2" />
    </el-form-item>
    <el-form-item label="排量/变速箱">
      <el-input v-model="formLabelAlign.gearbox" :disabled="formLabelAlign.energy === 2" />
    </el-form-item>
    <el-form-item label="联系电话">
      <el-input v-model="formLabelAlign.phone" />
    </el-form-item>
    <el-form-item label="车辆描述">
      <el-input :rows="2" type="textarea" v-model="formLabelAlign.description" />
    </el-form-item>
    <el-form-item label="所需积分">
      <el-input-number v-model="formLabelAlign.useCoin">
      </el-input-number>
    </el-form-item>
  </el-form>
  <el-button type="primary" @click="submitData">提交</el-button>
</template>

<style lang="less" scoped>
</style>